package table.models;

import java.util.LinkedList;

import javax.swing.table.AbstractTableModel;

public class ColorChosingTableModel extends AbstractTableModel {

	private String [] columnNames = { "1", "2", "3", };
	private final LinkedList < Object [] > data = new LinkedList < Object [] >();

	public int getColumnCount() {
		return this.columnNames.length;
	}

	public int getRowCount() {
		return this.data.size();
	}

	public void setColumnNames(String [] columnNames) {
		this.columnNames = columnNames;
	}

	public void addRow(Object [] rowData) {
		this.data.add(rowData);
	}

	@Override
	public String getColumnName(int col) {
		return this.columnNames [col];
	}

	public Object getValueAt(int row, int col) {
		return this.data.get(row) [col];
	}

	/*
	 * JTable uses this method to determine the default renderer/ editor for
	 * each cell. If we didn't implement this method, then the last column would
	 * contain text ("true"/"false"), rather than a check box.
	 */
	@Override
	public Class getColumnClass(int c) {
		return this.getValueAt(0, c).getClass();
	}

	@Override
	public boolean isCellEditable(int row, int col) {
		// Note that the data/cell address is constant,
		// no matter where the cell appears onscreen.
		if (col < 1) {
			return false;
		} else {
			return true;
		}
	}

	@Override
	public void setValueAt(Object value, int row, int col) {

		this.data.get(row) [col] = value;
		this.fireTableCellUpdated(row, col);
	}
}
